<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>离职人员工作交接</title>
    <script src="../../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../../../../res/js/error.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../../res/layui/css/layui.css" media="all">
    <style type="text/css">
        .connect {
            display: flex;
            align-items: center;
            margin-right: 0px !important;
        }

        .connectone {
            margin-top: 3px !important;
            width: calc(100% - 145px) !important;

        }
    </style>
</head>
<body style="padding: 10px">
<h1 align="center" style="margin-bottom: 20px">离职人员工作交接申请(交接人填写)</h1>
<form class="layui-form layui-form-pane" action="">
    <div class="layui-form-item">
        <input type="hidden" id="pkDimissionId" name="pkDimissionId"/>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">姓名</label>
            <div class="layui-input-inline">
                <!--<select name="personnelId" id="personnelId" lay-filter="aihao" lay-search="">
                    <option value="" selected="">请选择</option>
                </select>-->
                <input autocomplete="off" class="layui-input" lay-verify="required" disabled name="personnelName"
                       id="personnelName"
                       type="text"/>
                <input id="personnelId" type="hidden" name="personnelId"/>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">部门</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" lay-verify="required" disabled name="departmentName"
                       id="departmentName"
                       type="text"/>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">岗位</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" lay-verify="required" disabled name="stationone"
                       id="stationone"
                       type="text"/>
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">入职时间</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled id="entryTime" lay-verify="date" name="entryTime"
                       placeholder="yyyy-MM-dd"
                       type="text">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">离职日期</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" disabled id="dimissionCurrentDate"
                       name="dimissionCurrentDate"
                       placeholder="yyyy-MM-dd HH:mm:ss"
                       type="text">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label" style="width: 145px">交接人员</label>
            <div class="layui-input-inline">
                <input autocomplete="off" class="layui-input" lay-verify="required" name="personnelIds" disabled
                       id="personnelIds">

            </div>
        </div>
    </div>

    <div class="layui-form-item" pane="">
        <label class="layui-form-label">离职原因</label>
        <div class="layui-input-block">
            <input type="radio" id="dimissionType0" disabled name="dimissionCause" value="0" title="主动离职">
            <input type="radio" id="dimissionType1" disabled name="dimissionCause" value="1" title="辞退">
            <input type="radio" id="dimissionType2" disabled name="dimissionCause" value="2" title="其他">
        </div>
    </div>

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">部门交接</label>
        <div class="layui-input-block">

            <div class="layui-form-item">
                <div class="layui-inline connect">
                    <label class="layui-form-label" style="width: 145px">经管工作</label>
                    <div class="layui-input-inline connectone">

                        <input autocomplete="off" class="layui-input" lay-verify="required"
                               name="handoverDepartmentWork"
                               id="handoverDepartmentWork"
                               type="text"/>
                    </div>
                </div>
                <div class="layui-inline connect">
                    <label class="layui-form-label" style="width: 145px">文件资料</label>
                    <div class="layui-input-inline connectone">
                        <input autocomplete="off" class="layui-input" lay-verify="required"
                               id="handoverDepartmentDocumentation"
                               name="handoverDepartmentDocumentation"
                               type="text"/>
                    </div>
                </div>

                <div class="layui-inline connect">
                    <label class="layui-form-label" style="width: 300px">业务协作方有效联络人及联系电话</label>
                    <div class="layui-input-inline connectone">
                        <input autocomplete="off" class="layui-input" lay-verify="required"
                               name="handoverDepartmenContact"
                               id="handoverDepartmenContact"
                               type="text"/>
                    </div>
                </div>

                <div class="layui-form-item" pane="">
                    <label class="layui-form-label" style="width: 145px">电脑涉密资料确认</label>
                    <div class="layui-input-block " style="margin-left: 145px;">
                        <input type="radio" id="handoverDepartmentClassifiedInformation0"
                               name="handoverDepartmentClassifiedInformation"
                               value="0" title="已确认" checked="">
                        <input type="radio" id="handoverDepartmentClassifiedInformation1"
                               name="handoverDepartmentClassifiedInformation"
                               value="1" title="待确认"
                        >
                    </div>
                </div>

                <div class="layui-inline connect">
                    <label class="layui-form-label" style="width: 140px">其他</label>
                    <div class="layui-input-block connectone">
                        <input autocomplete="off" class="layui-input" lay-verify="required"
                               name="handoverOtherMatters"
                               id="handoverOtherMatters"
                               type="text"/>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入内容" id="handoverDepartmentRemark"
                                  name="handoverDepartmentRemark"
                                  class="layui-textarea"></textarea>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <hr/>

    <div class="layui-form-item">
        <div class="layui-input-block" id="flows">
            <button type="submit" class="layui-btn site-demo-active" lay-submit="" lay-filter="demo1">立即提交</button>
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="取消">
        </div>
    </div>
</form>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>流程日志</legend>
</fieldset>
<ul class="layui-timeline" id="schedule"></ul>
<script>
    var table2;
    // 修改赋值
    let pkDimissionId = getQueryString("pkDimissionId");
    let pkDimissionHandoverId= getQueryString("pkDimissionHandoverId");
    layui.use(['form', 'table', 'layedit', 'laydate'], function () {
        var table = layui.table
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , form = layui.form;
        // 入职日期
        laydate.render({
            elem: '#entryTime'
        });
        // 离职申请日期
        laydate.render({
            elem: '#dimissionCurrentDate'
        });
        // 正式离职日期
        laydate.render({
            elem: '#dimissionTime'
        });

        let res = getAjaxById(getRootPath() + "OaPersonnelAction/getUser");
        var resdata;
        if (!pkDimissionHandoverId) {
            resdata = getAjaxById(getRootPath() + "OaDimissionFlowAction/findById/" + pkDimissionId);
            // 离职人员id
            $("#personnelId").val(resdata.personnelId);
            console.log(resdata.dimissionCauseType);
            //离职原因
            $("input[name=dimissionCause][value='0']").attr("checked", resdata.dimissionCauseType == 0 ? true : false); // 离职类型 试用期内离职
            $("input[name=dimissionCause][value='1']").attr("checked", resdata.dimissionCauseType == 1 ? true : false); // 离职类型 合同期内离职
            $("input[name=dimissionCause][value='2']").attr("checked", resdata.dimissionCauseType == 2 ? true : false); // 离职类型 合同到期
            //离职人员名称
            $("#personnelName").val(resdata.createdBy);

            // 填表日期
            $("#entryTime").val(dateFormat('yyyy-MM-dd', new Date(resdata.entryTime)));
            //正式离职日期
            $("#dimissionCurrentDate").val(dateFormat('yyyy-MM-dd', new Date(resdata.dimissionTime)));
            const getres = getAjaxById(getRootPath() + "OaPersonnelAction/findById/" + resdata.personnelId);
            // 离职人员部门
            $("#departmentName").val(getres.data.departmentName);
            //离职人员岗位
            $("#stationone").val(getres.data.postName);
            //赋值人员下拉框
            $("#personnelIds").val(res.personnelName);
            form.render();
        }else {
            resdata = getAjaxById(getRootPath() + "OaDimissionHandoverAction/selectById/" + pkDimissionHandoverId);
            $("#personnelId").val(res.pkPersonnelId);
            //离职原因
            $("input[name=dimissionCause][value='0']").attr("checked", resdata.dimissionCauseType == 0 ? true : false); // 离职类型 试用期内离职
            $("input[name=dimissionCause][value='1']").attr("checked", resdata.dimissionCauseType == 1 ? true : false); // 离职类型 合同期内离职
            $("input[name=dimissionCause][value='2']").attr("checked", resdata.dimissionCauseType == 2 ? true : false); // 离职类型 合同到期
            //离职人员名称
            $("#personnelName").val(resdata.personnelName);
            // 离职人员部门
            $("#departmentName").val(resdata.departmentName);
            //离职人员岗位
            $("#stationone").val(resdata.postName);
            // 填表日期
            $("#entryTime").val(dateFormat('yyyy-MM-dd', new Date(resdata.entryTime)));
            //正式离职日期
            $("#dimissionCurrentDate").val(dateFormat('yyyy-MM-dd', new Date(resdata.dimissionTime)));
            //交接人员
            $("#personnelIds").val(resdata.createdBy);
            //经管工作
            $("#handoverDepartmentWork").val(resdata.handoverDepartmentWork);
            //文件资料
            $("#handoverDepartmentDocumentation").val(resdata.handoverDepartmentDocumentation);
            //业务协作方有效联络人及联系电话
            $("#handoverDepartmenContact").val(resdata.handoverDepartmenContact);
            console.log(resdata.handoverDepartmentClassifiedInformation);
            //电脑涉密资料确认
            $("input[name=handoverDepartmentClassifiedInformation][value='0']").attr("checked", resdata.handoverDepartmentClassifiedInformation == 0 ? true : false); //确认
            $("input[name=handoverDepartmentClassifiedInformation][value='1']").attr("checked", resdata.handoverDepartmentClassifiedInformation == 1 ? true : false); //待确认
            //其他
            $("#handoverOtherMatters").val(resdata.handoverOtherMatters);
            //备注
            $("#handoverDepartmentRemark").val(resdata.handoverDepartmentRemark);
            form.render();

            const resss = getAjaxById(getRootPath() + "OaFlowAction/selectFlowSchedule/" + pkDimissionHandoverId);
            $("#schedule").html("");
            $.each(resss, function (index, item) {
                if (item.createdBy) {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '            <p>操作人：' + item.createdBy + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')

                } else {
                    $("#schedule").append('<li class="layui-timeline-item">\n' +
                        '        <i class="layui-icon layui-timeline-axis"></i>\n' +
                        '        <div class="layui-timeline-content layui-text">\n' +
                        '            <h3 class="layui-timeline-title">' + dateFormat('yyyy-MM-dd hh:mm:ss', new Date(item.createdTime)) + '&nbsp;&nbsp;&nbsp;' + item.flowName + '</h3>\n' +
                        '            <p>' + item.formReason + '</p>\n' +
                        '        </div>\n' +
                        '    </li>')
                }
            });


        }
        /*if (pkDimissionId){
                   $("#flows").hide();
               }else{
                   $("#flowTwo").hide();
        }*/

        //监听提交
        form.on('submit(demo1)', function (data) {

            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');

            let datas = {

                handoverDepartmentWork: $("#handoverDepartmentWork").val(), // 经管工作
                handoverDepartmentDocumentation: $("#handoverDepartmentDocumentation").val(), // 文件，资料
                handoverDepartmenContact: $("#handoverDepartmenContact").val(), // 有效联络人及联系电话
                pname: $("#personnelName").val(),
                handoverOtherMatters: $("#handoverOtherMatters").val(), //其他事项
                handoverDepartmentRemark: $("#handoverDepartmentRemark").val(), // 备注
                DimissionId: pkDimissionId,// id
                pkDimissionHandoverId: pkDimissionHandoverId //交接ID

            };
            datas.handoverDepartmentClassifiedInformation = $("input[name='handoverDepartmentClassifiedInformation']").val(); // 电脑涉密资料
            console.log(datas);
            debugger
            let res = postAjax(getRootPath() + "OaDimissionHandoverAction/addHover", datas);


            //console.info("调用请求");
            if (res === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    //window.parent.location.reload();//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3001);
                //window.location.reload();//刷新页面
            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#demo3").on("click", function () {
            //询问框
            layer.confirm('是否关闭该页面？', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                formClose();
            });
        })

    });
</script>
</body>
</html>